#include <stdio.h>
#include <sys/wait.h>
#include <unistd.h>

int main(int argc, const char **argv) {
  int i = 0;
  pid_t pid;
  for (i = 0; i < 2; i++) {
    pid = fork();
    if (pid == 0)
      break;
  }

  if (i < 2) {
    printf("I am child,my pid is %d,my father pid is %d\n", getpid(),
           getppid());
    return i + 1;
  }

  int status;
  if (i == 2)
    while ((pid = wait(&status)) != -1) {
      if (WIFEXITED(status)) {
        printf("I am father and my child pid is %d,my child exit is %d\n", pid,
               (status) >> 8);
      }
    }

  return 0;
}
